package com.luozengliang.exam.entity;

import java.math.BigDecimal;
import java.math.RoundingMode;

public abstract class Fruit {

    //水果名称
    private String name;
    //单价
    private BigDecimal unitPrice;
    //重量,斤
    private BigDecimal weight;

    protected Fruit(String name, BigDecimal unitPrice, BigDecimal weight){
        this.name = name;
        //单价取两位小数
        this.unitPrice = unitPrice.setScale(2, RoundingMode.HALF_UP);
        //重量取三位小数
        this.weight = weight.setScale(3, RoundingMode.HALF_UP);

    }

    //获取总价
    public BigDecimal totalPrice(){
        return this.unitPrice.multiply(this.weight).setScale(2, RoundingMode.HALF_UP);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getUnitPrice() {
        return unitPrice;
    }

    public void setUnitPrice(BigDecimal unitPrice) {
        this.unitPrice = unitPrice;
    }

    public BigDecimal getWeight() {
        return weight;
    }

    public void setWeight(BigDecimal weight) {
        this.weight = weight;
    }
}
